{% extends "base.html" %}
{% load i18n %}
{% load bootstrap3 %}
{% load dv_filters %}
{% block head_title %}{% blocktrans with year=year season=dv_season|season_verb %}{{ season }} {{ year }}
{% endblocktrans %}{% endblock %}

{% block content %}
  <h1>{% blocktrans with year=year season=dv_season|season_verb %}{{ season }} {{ year }}{% endblocktrans %}</h1>

  <nav>
    <ul class="pager">
      <li class="previous btn-xs">
        <a href="{% dv_season_url dv_season_prev_day %}">
          {% dv_season dv_season_prev_day as dvs %}
          <span aria-hidden="true">&larr;</span>
          {% blocktrans with year=dvs.year season=dvs.dv_season|season_verb %}{{ season }} {{ year }}{% endblocktrans %}
        </a>
      </li>
      {% dv_season as dvs %}
      {% if year|add:0 != dvs.year|add:0 or dv_season|add:0 != dvs.dv_season|add:0 %}
        <li class="btn-xs">
          <a href="{% dv_season_url %}">{% trans "Saison courante" %}</a>
        </li>
      {% endif %}
      <li class="next btn-xs">
        <a href="{% dv_season_url dv_season_next_day %}">
          {% dv_season dv_season_next_day as dvs %}
          {% blocktrans with year=dvs.year season=dvs.dv_season|season_verb %}{{ season }} {{ year }}{% endblocktrans %}
          <span aria-hidden="true">&rarr;</span>
        </a>
      </li>
    </ul>
  </nav>

  <table class="table">
    {% for season in seasons %}
      <tr class="{{ season.state_class }}">
        <td>{{ season.state_icon }}</td>
        <td>
          {% if user|can:'challenge_season_crud' and user|anyofusercantons:season.cantons or user == season.leader or user|unprivileged_user_can_see:season or user in season.all_coordinator_qs %}
            <a href="{% url 'season-detail' pk=season.pk %}" title="{% trans "Liste des sessions" %}">
          {% elif season.staff_can_update_availability and user.profile.is_paid_staff %}
            <a href="{% url 'season-availabilities-update' pk=season.pk helperpk=request.user.pk %}"
               title="{% trans "Mes disponibilités" %}">
          {% endif %}
          <span class="badge pull-right">{{ season.leader.get_full_name }}</span>
          {{ season.desc_abbr }}
          {% if user|can:'challenge_season_crud' and user|anyofusercantons:season.cantons or season.staff_can_update_availability or season.staff_can_see_planning or user in season.all_coordinator_qs %}
            </a>
          {% endif %}
        </td>
        <td>
          {% if user|can:'challenge_season_crud' and user|anyofusercantons:season.cantons or user == season.leader %}
            <a class="btn btn-xs btn-primary" href="{% url 'season-availabilities' season.pk %}"
               title="{% trans "Planning" %}"><span class="glyphicon glyphicon-th"></span></a>
          {% elif season.staff_can_update_availability and user.profile.is_paid_staff %}
            <a class="btn btn-xs btn-default"
               href="{% url 'season-availabilities-update' pk=season.pk helperpk=request.user.pk %}"
               title="{% trans "Mes disponibilités" %}"><span class="glyphicon glyphicon-calendar"></span></a>
          {% endif %}
          {% if season.staff_can_see_planning %}
            <a class="btn btn-xs btn-default" href="{% url 'season-planning' pk=season.pk helperpk=request.user.pk %}"
               title="{% trans "Mon planning" %}"><span class="glyphicon glyphicon-calendar"></span></a>
          {% endif %}
        </td>
      </tr>
    {% endfor %}
    {% if seasons %}
      <tr>
        <td colspan="2" class="text-right">
          <strong>{% trans "Planning général" %}</strong>
        </td>
        <td>
          <a class="btn btn-xs btn-default" href="{% url 'season-general-planning' year=year dv_season=dv_season helperpk=request.user.pk %}"
             title="{% trans "Mon planning" %}"><span class="glyphicon glyphicon-calendar"></span></a>
        </td>
      </tr>
    {% endif %}
  </table>

  {% if user|can:'challenge_season_crud' %}
    <div>
      <a class="btn btn-primary pull-right" href="{% url 'season-create' %}">{% trans "Créer un nouveau mois" %}</a>
    </div>
  {% endif %}
{% endblock %}
